<template>
  <!-- 日常监督 -->
  <div class="rcjdPage" id="rcjd_echarts"></div>
</template>

<script>
import { getRcjd } from "../utils/api";
export default {
  props: ["RcjdData"],
  data() {
    return {
      rcjdList: [],
      xData: [],
      yData: [],
    };
  },
  mounted() {
    this.handleGetRcjd();
    setTimeout(() => {
      this.drawChart();
    }, 1000);
  },
  methods: {
    handleGetRcjd() {
      getRcjd().then((res) => {
        this.rcjdList = res.data;
        this.xData = res.data.map((item) => item.companyName);
        this.yData = res.data.map((item) => item.score);
      });
    },
    drawChart() {
      var myChart = this.$echarts.init(document.getElementById("rcjd_echarts"));
      var option = {
        tooltip: {
          trigger: "none",
          axisPointer: {
            type: "none",
          },
        },
        grid: {
          top: "20%",
          left: "6%",
          right: "6%",
          bottom: "12%",
          containLabel: true,
        },
        xAxis: [
          {
            type: "category",
            data: this.xData,
            axisTick: {
              alignWithLabel: true,
            },
            axisLabel: {
              interval: 0,
              margin: 30,
              textStyle: {
                color: "#d0e0fe",
              },
            },
            axisLine: {
              lineStyle: {
                color: "#152f60",
              },
            },
          },
        ],
        yAxis: [
          {
            type: "value",
            axisLabel: {
              show: false,
            },
            axisLine: {
              lineStyle: {
                color: "#48618f",
              },
            },
            splitLine: {
              show: true,
              lineStyle: {
                color: "#143162",
                type: "dotted",
              },
            },
          },
        ],
        series: [
          {
            name: "Direct",
            type: "bar",
            barWidth: "20",
            data: this.yData,
            label: {
              show: true,
              position: "top",
              color: "#81adff",
            },
            itemStyle: {
              color: {
                type: "linear",
                x: 0,
                y: 0,
                x2: 0,
                y2: 1,
                colorStops: [
                  {
                    offset: 0,
                    color: "rgba(20,146,253,1)",
                  }, // 0% 处的颜色
                  {
                    offset: 1,
                    color: "rgba(20,146,253,0)",
                  }, // 100% 处的颜色
                ],
                global: false, // 缺省为 false
              },
              emphasis: {
                color: {
                  type: "linear",
                  x: 0,
                  y: 0,
                  x2: 0,
                  y2: 1,
                  colorStops: [
                    {
                      offset: 0,
                      color: "rgba(14,249,222,1)",
                    }, // 0% 处的颜色
                    {
                      offset: 1,
                      color: "rgba(14,249,222,0)",
                    }, // 100% 处的颜色
                  ],
                  global: false, // 缺省为 false
                },
              },
            },
          },
        ],
      };
      myChart.setOption(option);
      // 鼠标移入改变X轴文字颜色
      myChart.on("mouseover", function (params) {
        if (params.componentType === "series") {
          var dataIndex = params.dataIndex;
          myChart.setOption({
            xAxis: {
              axisLabel: {
                color: function (value, index) {
                  return index === dataIndex ? "rgba(14,249,222,1)" : "#d0e0fe";
                },
              },
            },
          });
        }
      });
      myChart.on("mouseout", function (params) {
        myChart.setOption({
          xAxis: {
            axisLabel: {
              color: "#d0e0fe",
            },
          },
        });
      });
      // 图表自适应
      myChart.setOption(option);
      window.addEventListener("resize", function () {
        myChart.resize();
      });
    },
  },
};
</script>

<style lang="scss" scoped>
.rcjdPage {
  width: 100%;
  height: 100%;
  overflow: hidden;
  transition: 0.5s;
}
</style>
